package chapter05;

import java.nio.charset.StandardCharsets;

public class Test01_String {
    public static void main(String[] args) {
        //初始化字符串
        String s1 = "abc";
        String s2 = new String("abc");
        //使用char类型的数组
        char[] c = {'a','b','c','d'};
        String s3 = new String(c);
        //使用byte类型的数组
        byte[] b = new byte[]{97,98,99,100};
        String s4 = new String(b);
        System.out.println(s1);
        System.out.println(s2);
        System.out.println(s3);
        System.out.println(s4);
        System.out.println("1"+2);
        System.out.println(1+2);
        //字符串的常用方法
        String s5 = "abcdefg123456e";
        //字符串的长度
        System.out.println(s5.length());
        //取得字符串的第4个元素
        System.out.println(s5.charAt(3));
        //查询字符的位置
        System.out.println(s5.indexOf('e'));
        System.out.println(s5.lastIndexOf('e'));
        System.out.println(s5.indexOf("bc"));
        //将字符串转换成char类型的数组
        char[] chars = s5.toCharArray();
        for(char i:chars){
            System.out.print(i);
            System.out.print(" ");
        }
        System.out.println();
        //转换成byte类型的数组
        byte[] bytes = s5.getBytes(StandardCharsets.UTF_8);
        for(int i=0;i<bytes.length;i++){
            System.out.print(bytes[i]);
            System.out.print(" ");
        }
        System.out.println();
        System.out.println(String.valueOf(20));
        System.out.println(s5.toUpperCase());

    }
}
